package red_book.year2024.month9;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 5
 * 1 2 1 2 1
 * 0 1 1 0 1
 *
 * 1
 */
public class Beauti {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int n=sc.nextInt();
        int[][]arr=new int[2][n];
        for(int i=0;i<2;i++){
            for(int j=0;j<n;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        sc.close();
        List<int[]>list=new ArrayList<>();
        for(int i=0;i<n;i++){
            int[]temp=new int[2];
            temp[0]=arr[0][i];
            temp[1]=arr[1][i];
            list.add(temp);
        }
        int l=0,r=n-1;
        while(l<r){
            while(l<r&&list.get(l)[0]==1&&list.get(l)[1]==0){
                l++;
            }
            while(r>l&&list.get(r)[0]==2&&list.get(r)[1]==0){
                r--;
            }
            // 交换
            int []temp=list.get(l);
            list.set(l,list.get(r));
            list.set(r,temp);
            l++;
            r--;
        }
        int last=list.get(0)[0];
        int count=0;
        for(int i=1;i<n;i++){
            if(list.get(i)[0]!=last){
                count++;
            }
            last=list.get(i)[0];
        }
        System.out.println(count);
    }
}
